Component({
  options: {
    styleIsolation: 'apply-shared' //页面样式将影响到组件,但组件中指定的样式不会影响页面
  },
  properties: {
    firstList: {
      type: Array,
      value: []
    },
    secondList: {
      type: Array,
      value: []
    },
    threeList: {
      type: Array,
      value: []
    },
    fourList: {
      type: Array,
      value: []
    }
  },
  data: {
    isShow: false, //是否显示
    title: '请选择省', //标题
    areaOne: '', //省
    areaOneCode: '', //省code
    areaTwo: '', //市
    areaTwoCode: '', //市code
    areaThree: '', //区
    areaThreeCode: '', //区code
    type: '', //类型
    isShowLevenFour: false,
  },
  methods: {
    /**
     * 显示弹窗
     */
    showPicker() {
      this.setData({
        isShow: true,
      })
    },
    /**
     * 隐藏弹窗
     */
    pickerCancel() {
      this.setData({
        isShow: false,
      })
      this.triggerEvent('comfirmArea', {
        status: true
      })
    },
    /**
     * 选择省
     */
    chooseProvince(e) {
      var code = e.currentTarget.dataset.itemcode;
      var name = e.currentTarget.dataset.itemname;
      this.setData({
        title: '请选择市',
        areaOne: name,
        areaOneCode: code
      })
      this.triggerEvent('showAreaTwo', {
        code: code,
        name: name
      })
    },
    /**
     * 返回上一级
     */
    clearArea() {
      if (this.data.areaThree) {
        this.setData({
          title: '请选择区',
          areaThree: '',
        })
      } else
      if (this.data.areaTwo) {
        this.setData({
          title: '请选择市',
          areaTwo: '',
        })
      } else {
        this.setData({
          title: '请选择省',
          areaOne: '',
        })
      }
    },
    /**
     * 选择市
     */
    chooseCity(e) {
      var code = e.currentTarget.dataset.itemcode
      var name = e.currentTarget.dataset.itemname
      var mername = e.currentTarget.dataset.itemmername
      var lat = e.currentTarget.dataset.itemlat
      var lng = e.currentTarget.dataset.itemlng
      this.setData({
        title: '请选择区',
        areaTwo: name,
        areaTwoCode: code
      })
      this.triggerEvent('showAreaThree', {
        code: code,
        name: name,
        mername: mername,
        lat: lat,
        lng: lng
      })
    },
    /**
     * 选择区
     */
    chooseThree(e) {
      var code = e.currentTarget.dataset.itemcode
      var name = e.currentTarget.dataset.itemname
      var mername = e.currentTarget.dataset.itemmername
      var lat = e.currentTarget.dataset.itemlat
      var lng = e.currentTarget.dataset.itemlng
      this.setData({
        isShow: (code == 511123 && (this.data.type == 'address' || this.data.type == 'workAddress' || this.data.type == 'cardAddress' || this.data.type == 'nowAddressCollect' || this.data.type == 'regAddress' ||
          this.data.type == 'nowAddress' || this.data.type == 'expectJobAdress')) ? true : false,


      })
      //犍为县
      if (code == 511123 && (this.data.type == 'address' || this.data.type == 'workAddress' || this.data.type == 'cardAddress' || this.data.type == 'nowAddressCollect' || this.data.type == 'regAddress' ||
          this.data.type == 'nowAddress' || this.data.type == 'expectJobAdress')) {
        this.setData({
          title: '请选择街道/镇',
          isShowLevenFour: true,
          areaThree: name, //区
          areaThreeCode: code, //区code
        })
        this.triggerEvent('showAreaFour', {
          code: code,
          name: name,
          mername: mername,
          lat: lat,
          lng: lng
        })
      } else {
        this.setData({
          isShowLevenFour: false,
          areaThree: "", //区
          areaThreeCode: "", //区code
        })
        this.triggerEvent('comfirmAreaThree', {
          status: true,
          code: code,
          name: name,
          mername: mername,
          lat: lat,
          lng: lng
        })
      }

    },
    /**
     * 选择区
     */
    chooseFour(e) {
      var code = e.currentTarget.dataset.itemcode
      var name = e.currentTarget.dataset.itemname
      var mername = e.currentTarget.dataset.itemmername
      var lat = e.currentTarget.dataset.itemlat
      var lng = e.currentTarget.dataset.itemlng
      this.setData({
        isShow: false,
        areaFour: name, //区
        areaFourCode: code, //区code
      })
      this.triggerEvent('comfirmAreaFour', {
        status: true,
        code: code,
        name: name,
        mername: mername,
        lat: lat,
        lng: lng
      })

    },
    /**
     * 设置标志
     */
    setType(type) {
      this.setData({
        type: type
      })
    },
    /**
     * 获取标志
     */
    getType() {
      return this.data.type
    },
    /**
     * 清除选择地址
     */
    clearAddress() {
      this.setData({
        title: '请选择省',
        areaOne: '',
        areaTwo: '',
        areaThree: ''
      })
    }

  }
})